/**
 * @class Ext.app.DanhSachMatHangLookup
 * @extends Ext.panel.Window
 */
Ext.define('Ext.app.DanhSachMatHangLookup', {
    extend: 'Ext.window.Window',
    alias: 'widget.dsMatHangLookup',

    initComponent : function() {
        Ext.getBody().mask();
        Ext.apply(this, {
            height: 500,
            width: 900,
            bodyPadding: 5,
            layout: 'border',
            items: [
                {
                    region: 'center',
                    xtype: 'gridpanel',
                    columnLines: true,
                    store: {
                        fields: ['prodPK', 'code', 'madeIn', 'nameBySupplier', 'nameForSell', 'type'],
                        autoLoad: true,
                        pageSize: 25,
                        proxy: {
                            type: 'ajax',
                            url: 'DanhSachMatHang.jsp',
                            reader: {
                                type: 'json',
                                root: 'root',
                                totalProperty: 'totalCount'
                            }
                        }
                    },
                    columns: [{
                        text: translations.get("HOME.PRODUCT_CODE"),
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'code',
                        width: 150
                    },{
                        text: translations.get("HOME.PRODUCT_NAME_BY_SUPPLIER"),
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'nameBySupplier',
                        width: 250
                    },{
                        text: translations.get("HOME.PRODUCT_NAME_FOR_SELL"),
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'nameForSell',
                        width: 250
                    },{
                        text: translations.get("HOME.XUAT_XU"),
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'madeIn',
                        width: 120
                    },{
                        text: translations.get("HOME.LOAI_HANG_HOA"),
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'type',
                        width: 100
                    }],
                    viewConfig: {
                        loadingText: translations.get("HOME.PLEASE_WAIT"),
                        stripeRows: true
                    },
                    listeners: {
                        cellclick: function(table, td, cellIndex, record, tr, rowIndex, e, eOpts) {
                            var wind = table.up('window');
                            wind.opener.onSelectRecord({
                                prodPK: record.get("prodPK"),
                                code: record.get("code"),
                                madeIn: record.get("madeIn"),
                                nameBySupplier: record.get("nameBySupplier"),
                                nameForSell: record.get("nameForSell"),
                                type: record.get("type")
                            });
                            wind.close();
                        }
                    },
                    afterFirstLayout: function() {
                        // paging bar on the bottom [
                        var bbar = Ext.create('Ext.PagingToolbar', {
                            store: this.getStore(),
                            beforePageText: 'Trang',
                            afterPageText: '/ {0}'
                        });
                        bbar.dock = "bottom";
                        this.addDocked(bbar);
                        //]
                    }
                }
            ]            
        });
        this.callParent();
    },
    
    listeners: {
        beforeclose: function () {
            Ext.getBody().unmask();
        }
    },
    
    setOpener: function(opener) {
        this.opener = opener;
    }
});
